﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NRCP
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

      

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                String userName = tbxEmailAddress.Text.Trim();
                String password = tbxPassword.Text.Trim();
                HttpCookie cookie = System.Web.Security.FormsAuthentication.GetAuthCookie(userName, cbxRemember.Checked);
                // Extract the ticket
                System.Web.Security.FormsAuthenticationTicket ticket = System.Web.Security.FormsAuthentication.Decrypt(cookie.Value);
                // Create the new identity for this request
                System.Web.Security.FormsIdentity identity = new System.Web.Security.FormsIdentity(ticket);
                // Apply it.
                Context.User = new System.Security.Principal.GenericPrincipal(identity, new string[] { "admin" });
                Context.Response.Cookies.Add(cookie);
                SessionManager.LOGGEDIN_USER_NAME = userName;
                System.Web.Security.FormsAuthentication.RedirectFromLoginPage(userName, cbxRemember.Checked);
                if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["ReturnUrl"].ToLower()))
                {
                    HttpContext.Current.Response.Redirect(HttpContext.Current.Request.QueryString["ReturnUrl"]);
                }
                else
                {
                    HttpContext.Current.Response.Redirect("~/default.aspx");
                }
            }
            catch (Exception ex)
            {

            }
        }

       
    }
}